//
//  networkViewController.m
//  fugitiveVertical
//
//  Created by Eugene Bistolas on 5/12/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "networkViewController.h"


@implementation networkViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"Server API";
    }
    return self;
}

- (void)dealloc
{
    [networkText release];
    [introButton release];
    [rawButton release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    seng = [[[ServerEngine alloc] init] autorelease];
    UIImage *normalImg = [[UIImage imageNamed:@"regular.png"] stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    UIImage *highlightImg = [[UIImage imageNamed:@"hover.png"] stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    UIImage *activeImg = [[UIImage imageNamed:@"active.png"] stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    
    [rawButton setBackgroundImage:normalImg forState:UIControlStateNormal]; 
    [rawButton setBackgroundImage:highlightImg forState:UIControlStateHighlighted];
    [rawButton setBackgroundImage:activeImg forState:UIControlStateSelected];
    [introButton setBackgroundImage:normalImg forState:UIControlStateNormal]; 
    [introButton setBackgroundImage:highlightImg forState:UIControlStateHighlighted];
    [introButton setBackgroundImage:activeImg forState:UIControlStateSelected];
    
}

- (void)viewDidUnload
{
    [networkText release];
    networkText = nil;
    [introButton release];
    introButton = nil;
    [rawButton release];
    rawButton = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction) buttonPressed:(UIButton *)sender {
    if (sender.tag == 1) {
        NSString *data =[NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://dl.dropbox.com/u/403983/introTextfile.html"] encoding:NSASCIIStringEncoding error:nil];
        NSLog(@"Read server data\n");
        networkText.text = nil;
        networkText.text = data; 
    }
    if (sender.tag == 2) {
        NSString *data =[NSString stringWithContentsOfURL: [NSURL URLWithString: @"http://dl.dropbox.com/u/403983/textfile.html"] encoding:NSASCIIStringEncoding error:nil];
        NSLog(@"Read server data\n");
        networkText.text = nil; 
        networkText.text = data; 
    }

}

@end
